package jp.sourceforge.akjrcp.ui.param;

import jp.sourceforge.akjrcp.commons.ui.FileDirChoicer2;
import jp.sourceforge.akjrcp.commons.ui.AbstractFileDirChoicer.FileStatusChangeEvent;
import jp.sourceforge.akjrcp.commons.ui.AbstractFileDirChoicer.FileStatusChangeListener;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;

//TODO support all type
public class ParamFile2 extends AbstractParamCompositeItem{

	public ParamFile2(Composite parent, int style,String key,String label,int type,boolean reset) {
		super(parent, style);
		this.setLayout(new FillLayout());
		fileDirChoicer = new FileDirChoicer2(this,SWT.NULL,type,label,reset);
		fileDirChoicer.addFileListChangeListener(new FileStatusChangeListener(){

			@Override
			public void addList(FileStatusChangeEvent event) {
				if(paramActionListener!=null){
					paramActionListener.paramItemModified(self);
				}
			}

			@Override
			public void removeList(FileStatusChangeEvent event) {
				if(paramActionListener!=null){
					paramActionListener.paramItemModified(self);
				}
			}});
		this.key=key;
		this.label=label;
	}

	private String key;
	private String label;
	private String value;//for modified check
	private FileDirChoicer2 fileDirChoicer;
	
	public FileDirChoicer2 getFileDirChoicer(){
		return fileDirChoicer;
	}
	@Override
	public String getKey() {
		return key;
	}

	@Override
	public String getValue() {
		return fileDirChoicer.getAbsoluteFilePath();
	}

	@Override
	public boolean isModified() {
		String oldValue=getValue();
		return !oldValue.equals(value);
	}

	@Override
	public void setValue(String value) {
		fileDirChoicer.setFilePath(value);
		this.value=value;
	}
	public void setEnabled(boolean bool){
		super.setEnabled(bool);
		fileDirChoicer.setEnabled(bool);
	}

}
